<template>
  <div class="mod-config">
    <basic-container>
        <navigationZhuanX :sign="{a:true,b:false,c:false,d:false,e:false}"></navigationZhuanX>
        <div class="boxsty zhiBiao">
            <div  :height="searchheight" >
                <span style="float:right;margin-top: -30px;cursor: pointer;" @click="searchchangeadvanced">{{ searchadvanced ? "收起" : "展开" }}
                <i :class="searchadvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'" /> </span>
                <div  v-show="searchadvanced" >
                    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()"  class="form-inline">
                        <el-form-item label="工作名称">
                            <el-input v-model="dataForm.workName" placeholder="工作名称" :clearable="true"></el-input>
                        </el-form-item>
                        <el-form-item label="姓名">
                            <el-input v-model="dataForm.cyryname" placeholder="姓名" :clearable="true"></el-input>
                        </el-form-item>
                        <el-form-item label="职务">
                            <el-input v-model="dataForm.duties" placeholder="职务" :clearable="true"></el-input>
                        </el-form-item>
                        <el-form-item label="结束时间">
                            <el-date-picker
                                v-model="dataForm.endDate"
                                type="date"
                                format="yyyy-MM-dd"
                                value-format="yyyy-MM-dd"
                                placeholder="选择日期">
                            </el-date-picker>
                        </el-form-item>
                        <el-form-item>
                            <el-button icon="el-icon-search" type="primary" class="marginLeft"
                                        @click="getDataList(1)">检索
                            </el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
            <div>
                专项工作
                <div style="float:right">
                    <el-button v-if="showZ==2" type="primary" @click="scBatch">批量生成结果</el-button>
                    <el-button v-if="showZ==1" type="primary" @click="saveBatch">批量提交</el-button>
                    <el-button v-if="showZ==1" type="primary" @click="rateBulk">批量打分</el-button>
<!--                    <el-button v-if="showZ==1" type="primary">导入</el-button>-->
                    <el-button type="primary">导出</el-button>
                </div>
            </div>
            <el-table
                style="width: 100%;margin-top:20px"
                :data="dataList"
                border
                v-loading="dataListLoading"
                ref="tableRef">
                <el-table-column type="selection" width="55" header-align="center" align="center"></el-table-column>
                <el-table-column type="index" width="80" header-align="center" align="center" label="序号"></el-table-column>
                <el-table-column
                    prop="workName"
                    header-align="center"
                    align="center"
                    label="工作名称">
                </el-table-column>
                <el-table-column
                    prop="cyryname"
                    header-align="center"
                    align="center"
                    label="姓名">
                </el-table-column>
                <el-table-column
                    prop="duties"
                    header-align="center"
                    align="center"
                    label="职务">
                </el-table-column>
                <el-table-column
                    prop="endDate"
                    header-align="center"
                    align="center"
                    label="结束时间">
                </el-table-column>
                <el-table-column
                    prop="score"
                    header-align="center"
                    align="center"
                    v-if="showZ==1"
                    label="得分">
                    <template slot-scope="scope">
                        <el-input type="number" v-model="scope.row.score" placeholder=""></el-input>
                    </template>
                </el-table-column>
              <el-table-column
                prop="huizongScore"
                header-align="center"
                v-if="showZ==2"
                align="center"
                label="得分">
              </el-table-column>
                <el-table-column
                    header-align="center"
                    align="center"
                    fixed="right"
                    label="操作">
                    <template slot-scope="scope">
                    <el-button v-if="showZ==1" type="primary" :disabled="scope.row.hzstate!=0" plain size="small" @click="submit(scope.row)">提交</el-button>
                    <el-button v-if="showZ==2" type="primary" :disabled="scope.row.hzstate==0||scope.row.hzstate==2"plain size="small" @click="scResult(scope.row)">生成结果</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="avue-crud__pagination">
          <el-pagination
            @size-change="sizeChangeHandle"
            @current-change="currentChangeHandle"
            :current-page="pageIndex"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            :total="totalPage"
            background
            layout="total, sizes, prev, pager, next, jumper">
          </el-pagination>
        </div>
        <el-dialog  :close-on-click-modal="false" :visible.sync="visible" center width="30vw" top="8vh">
            <el-row>
              <el-col :span="24" style="text-align:center">
                  <h3 style="margin-top:0px;">批量打分</h3>
                  <el-table
                        style="width: 100%;margin-top:20px"
                        :data="dataList"
                        border
                        v-loading="dataListLoading">
                        <!-- <el-table-column type="selection" width="55" header-align="center" align="center"></el-table-column> -->
                        <!-- <el-table-column type="index" width="80" header-align="center" align="center" label="序号"></el-table-column> -->
                        <el-table-column
                            prop="workName"
                            header-align="center"
                            align="center"
                            label="工作任务">
                        </el-table-column>
                        <el-table-column
                            prop="cyryname"
                            header-align="center"
                            align="center"
                            label="姓名">
                        </el-table-column>
                        <el-table-column
                            prop="score"
                            header-align="center"
                            align="center"
                            label="分数">
                            <template slot-scope="scope">
                                <el-input type="number" v-model="scope.row.score" placeholder=""></el-input>
                            </template>
                        </el-table-column>
                      </el-table>
              </el-col>
            </el-row>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" plain @click="visible = false">保存</el-button>
            </span>
        </el-dialog>
    </basic-container>
  </div>
</template>

<script>
import {fetchList,submitScore,scResult,saveBatch,summaryList} from "@/api/hetongrenwu/zhuanxianggongzuo/zxgztianbao";

export default {
    name:"zhuanxiangtbhz-form",
    props:{
        showZ:0
    },
    data(){
        return{
            searchadvanced: true,
            searchheight: '0',
            dataForm:{},
            showZhong:1,
            dataList:[
                {}
            ],
            dataListLoading:false,
            visible:false
        }
    },
    created() {
      this.getDataList()
    },
    methods:{
        //批量打分
        rateBulk(){
            this.visible=true
        },
        //批量提交
        saveBatch(){
          const rows = this.$refs.tableRef.selection;
          if(rows.length > 0){
              this.$confirm('是否要通过' + rows.length + '条数据批量提交?','提示' ,{
                cancelButtonText: '否',
                confirmButtonText: '是',
                type: 'warning'
              }).then(() => {
                saveBatch(rows).then(response => {
                  this.$message({
                    type: 'success',
                    message: response.data.data + '条记录操作成功!'
                  });
                  this.$nextTick(() => {
                    this.getDataList();
                  })
                })
              }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消提交'
                });
              });

          }else{
            this.$message({
              type: 'info',
              message: '请选择一条记录提交!'
            });
          }
        },
        //批量生成
        scBatch(){
          const rows = this.$refs.tableRef.selection;
          if(rows.length > 0){
            this.$confirm('是否要通过' + rows.length + '条数据批量生成结果?','提示' ,{
              cancelButtonText: '否',
              confirmButtonText: '是',
              type: 'warning'
            }).then(() => {
              scBatch(rows).then(response => {
                this.$message.closeAll();
                this.$message({
                  type: 'success',
                  message: response.data.data + '条记录操作成功!'
                });
                this.$nextTick(() => {
                  this.getDataList();
                })
              })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消生成'
              });
            });

          }else{
            this.$message({
              type: 'info',
              message: '请选择一条记录生成!'
            });
          }
        },
        searchchangeadvanced() {
            this.searchadvanced = !this.searchadvanced;
            if(this.searchadvanced){
                this.searchheight= 'auto'
            }
        },
        //提交
        submit(row){
          if(row.score>100){
            this.$message.warning('分数不允许大于100！');
            return false;
          }else{
            this.$confirm('是否要提交该条数据?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              submitScore(row).then(res => {
                this.$message({
                  type: 'success',
                  message: '提交成功!'
                });
                this.getDataList()
              }).catch(() => {
                this.$message({
                  type: 'error',
                  message: '提交失败!'
                });
              })
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消提交'
              });
            });
          }
        },
      //生成结果
      scResult(row){
        this.$confirm('是否要提交该条数据?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          scResult(row).then(res => {
            this.$message({
              type: 'success',
              message: '提交成功!'
            });
            this.getDataList()
          }).catch(() => {
            this.$message({
              type: 'error',
              message: '提交失败!'
            });
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消提交'
          });
        });
      },
        // 获取数据列表
        getDataList() {
          this.dataListLoading = true
          if(this.showZ==1){
            fetchList(Object.assign({
              type:this.radio,
              workName:this.dataForm.workName,
              cyryname:this.dataForm.cyryname,
              duties:this.dataForm.duties,
              endDate:this.dataForm.endDate,
              current: this.pageIndex,
              size: this.pageSize
            })).then(response => {
              this.dataList = response.data.data.records
             //console.log(this.dataList)
              this.totalPage = response.data.data.total
            })
          }else if(this.showZ==2){
            summaryList(Object.assign({
              type:this.radio,
              workName:this.dataForm.workName,
              cyryname:this.dataForm.cyryname,
              duties:this.dataForm.duties,
              endDate:this.dataForm.endDate,
              current: this.pageIndex,
              size: this.pageSize
            })).then(response => {
              this.dataList = response.data.data.records
              this.totalPage = response.data.data.total
            })
          }
          this.dataListLoading = false
        },
        // 每页数
        sizeChangeHandle(val) {
          this.pageSize = val
          this.pageIndex = 1
          this.getDataList()
        },
        // 当前页
        currentChangeHandle(val) {
          this.pageIndex = val
          this.getDataList()
        },
    }
}
</script>

<style>

</style>
